package com.example.demo.action.common;/**
 * Created by kete on 2018-11-27.
 */

import io.netty.channel.socket.nio.NioSocketChannel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 作者：kete
 * 创建时间：2018-11-27 17:01
 * 功能描述：
 * 版本：
 */
public class NettySocketHolder {

    private static final Map<Long,NioSocketChannel> MAP = new ConcurrentHashMap<Long, NioSocketChannel>();

    public static void put(Long id,NioSocketChannel channel){
        MAP.put(id,channel);
    }

    public static void remove(Long id){
        MAP.remove(id);
    }

    public static Map<Long,NioSocketChannel> getMap(){
        return MAP;
    }

    public static NioSocketChannel get(Long id){
        return MAP.get(id);
    }

    public static void remove(NioSocketChannel channel){
        MAP.entrySet().stream().filter(entity->entity.getValue()==channel).forEach(entity->MAP.remove(entity.getKey()));
    }




}
